package com.example.gokuplayalong.bases.threadpool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class CustomThreadPoolExecutor {
    ThreadPoolExecutor threadPoolExecutor;
    private static CustomThreadPoolExecutor INSTANCE = null;

    public static CustomThreadPoolExecutor getInstance() {
        if (INSTANCE == null) INSTANCE = new CustomThreadPoolExecutor();
        return INSTANCE;
    }

    public CustomThreadPoolExecutor() {

        threadPoolExecutor = new ThreadPoolExecutor(10,
                20,
                1000,
                TimeUnit.MICROSECONDS,
                new ArrayBlockingQueue<Runnable>(100),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy());
    }

    public void execute(Runnable runnable) {
        threadPoolExecutor.execute(runnable);
    }
}
